﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Infraestruturex.BaseLibrary;

namespace Compilex.Syntatic
{
    public class CommandBlockStack
    {
        private SimpleStack<CommandBlock> CommandBlocksStack { get; set; }
        public SyntaticContext Context { get; set; }
        public CommandBlock Current
        {
            get
            {
                return CommandBlocksStack.Peek();
            }
        }
        public CommandBlockStack(SyntaticContext context)
        {
            this.Context = context;
            this.CommandBlocksStack = new SimpleStack<CommandBlock>();
            CommandBlocksStack.Push(new CommandBlock(context));
        }

        public void StartCommandBlock()
        {
            CommandBlocksStack.Push(new CommandBlock(Context));
        }

        public void EndCommandBlock()
        {
            CommandBlock ended = CommandBlocksStack.Pop();
            Current.ChildBlockEnded(ended);
        }

        public void StartIf()
        {
            Current.IfBlock.Start();
        }

        public void If_Else()
        {
            Current.IfBlock.Else();
        }

        public void EndIf()
        {
            Current.IfBlock.End();
        }

        public void StartWhileBeforeExpression()
        {
            Current.WhileBlock.StartBeforeExpression();
        }
        public void AfterWhileExpression()
        {
            Current.WhileBlock.AfterExpression();
        }
        public void EndWhile()
        {
            Current.WhileBlock.End();
        }
    }
}
